package com.nb.ds.service.impl;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import com.nb.ds.datasource.DS;
import com.nb.ds.datasource.DsConstant;
import com.nb.ds.entity.Student;
import com.nb.ds.entity.User;
import com.nb.ds.mapper.StudentMapper;
import com.nb.ds.mapper.UserMapper;
import com.nb.ds.service.IStudentService;
import com.nb.ds.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lihaoyang6
 * @date 2024年04月22日 15:24
 */
@Service
public class StudentServiceImpl implements IStudentService {

    @Autowired
    StudentMapper studentMapper;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @DS(DsConstant.ds2)
    @Override
    public List<Student> findAll() {
        return studentMapper.selectAll();
    }

    @DS(DsConstant.ds2)
    @Transactional
    @Override
    public void insert() {
        Student student = new Student();
        student.setStudentCode("Code-"+ RandomUtil.randomNumber());
        student.setStudentCode("学员-"+ RandomUtil.randomNumber());
        studentMapper.insertStu(student);
        int k=1/0;
    }
}
